// view/index/congye/congye.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    yiyao: '',
    heights: "",
    title: '从业人员',
    list: [],
    allstate: 1,
    page: 1,
  },
  Tel: function (e) {
    var tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel,
      success: function () {
        console.log("拨号成功！")
      },
      fail: function () {
        console.log("拨号失败！")
      }
    })
  },
  addyuanBaoji(){
    wx.navigateTo({
      url: '/page_one/addyuanBaoji/addyuanBaoji',
    })
  },
  // 删除员工
  delete(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    wx.showModal({
      title: '您确定要删除该员工吗？',
      cancelText: '否',
      confirmText: '是',
      success(res) {
        if (res.confirm) {
          console.log("是")
          that.shan(id)
        } else {
          console.log("否")
        }
      }
    })
  },
  shan(id) {
    var that = this
    this.myRequest(yuming + 'shop/shopDelStaff', {
      id: id,
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        that.cylist()
      }
    })
  },
  //点击放大
  fangda(e) {
    console.log(e)
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  // 列表
  cylist() {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shopSelectStaff', {
      page: that.data.page,
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        this.setData({
          list: res.data.result,
          // yu: res.data.Url,
          healthyCout: res.data.healthyCout,
          practiceCout: res.data.practiceCout,
          staffCout: res.data.staffCout
        })
        this.data.list.forEach(item => {
          item.jkzguoqi = false
          item.cyzguoqi = false
          if (new Date(item.effectiveTime).getTime() < Date.parse(new Date())) {
            item.jkzguoqi = true
          }
          if (new Date(item.practiceendTime).getTime() < Date.parse(new Date())) {
            item.cyzguoqi = true
          }
        })
        this.setData({
          list: this.data.list
        })
      }
    })
  },
  all() {
    if (this.data.allstate == 0) {
      this.setData({
        allstate: 1
      })
    } else {
      this.setData({
        allstate: 0
      })
    }
  },
  update(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/page_one/updateyuan/updateyuan?id=' + id,
    })
  },
  // 添加员工
  addyuan(e) {
    // console.log(e)
    // if (wx.getStorageSync('token') == "") {
    //   wx.showModal({
    //     title: '需要授权哦~',
    //     cancelText: '取消',
    //     confirmText: '确定',
    //     success: function (res) {
    //       if (res.confirm) {
    //         console.log("确定")
    //         wx.navigateTo({
    //           url: '/page_zhu/shou/shou?sta=66',
    //         })
    //       } else {
    //         console.log("取消")
    //         wx.navigateBack({
    //           delta: 0,
    //         })
    //       }
    //     }
    //   })
    // } else {
    var shen = e.currentTarget.dataset.shen
    var id = e.currentTarget.dataset.id
    // 0 添加 1 修改
    if (shen == 0) {
      wx.navigateTo({
        url: '/page_one/addyuan/addyuan',
      })
      wx.setStorageSync('zhan', 0)
    }
    if (shen == 1) {
      var Position = e.currentTarget.dataset.position
      console.log(Position)
      if (Position == "法人") {
        wx.navigateTo({
          url: '/page_one/xiuyuan/xiuyuan?Position=' + Position + "&id=" + id,
        })
      } else {
        wx.navigateTo({
          url: '/page_one/xiuyuan/xiuyuan?id=' + id,
        })
      }
    }
    // }

  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
    // wx.switchTab({
    //   url: '/pages/index/index',
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      jinghe_id:wx.getStorageSync('jinghe_id'),
      title: options.title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      yiyao: wx.getStorageSync('stryId')
    })
    this.cylist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})